package cn.bugstack.springframework.beans.factory.support;

import cn.bugstack.springframework.beans.BeansException;
import cn.bugstack.springframework.beans.factory.config.BeanDefinition;

/**
 * @author oyz
 */
public abstract  class AbstractAutowireCableBeanFactory extends AbstractBeanFactory{

    @Override
    public Object createBean(String beanName, BeanDefinition beanDefinition) throws BeansException {
        Object bean ;
        try {
            // 其实这块会埋下一个坑，有构造函数入参的对象怎么处理？可以提前思考
            bean = beanDefinition.getBeanClass().newInstance();

        } catch (InstantiationException |IllegalAccessException e) {
            throw new BeansException("Instantiation of bean failed",e);
        }
        // 把该bean放入ioc容器里边
        addSingleton(beanName,bean);
        return bean;
    }
}
